package com.gorkr;

/**
 * @author gorkr
 * @date 2022/01/18 12:28
 **/
public class J26 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A==null||B==null){
            return false;
        }
        if(A.val==B.val){
            if(checkSubtree(A,B)){
                return true;
            }
        }


        return isSubStructure(A.left,B) || isSubStructure(A.right,B);

    }

    // 处理null的情况
    public boolean checkSubtree(TreeNode A, TreeNode B){
        if(B==null){
            return true;
        }
        if(A==null||A.val!=B.val){
            return false;
        }
        return checkSubtree(A.left,B.right)&&checkSubtree(A.right, B.right);
    }
}
    